package com.wyh.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wyh.common.exception.CustomException;
import com.wyh.common.result.Result;
import com.wyh.domain.po.User;
import com.wyh.service.IUserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api("测试Controller")
public class testController {
    @Autowired
    private IUserService userService;

    @GetMapping ("/test/{id}")
    public Result test(@PathVariable(value = "id") int my){
        if (my==1){
            CustomException exception = new CustomException("520", "测试异常");
            throw exception;
        }
        return Result.error();
    }

    @GetMapping("/testMybatisPlus")
    public Result testMybatisPlus(){
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",1L);
        User one = userService.getOne(queryWrapper);
        return Result.success(one);
    }

    @GetMapping("/testMybatisXml")
    public Result testMybatisXML(){

        return userService.testXml(1L);
    }
}
